//
//  baseVC.swift
//  swiftDemo
//
//  Created by yaqiang bi on 2017/3/7.
//  Copyright © 2017年 毕小强. All rights reserved.
//

import UIKit
class baseVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        let btn = UIButton(type: UIButtonType.custom)
        btn.backgroundColor = UIColor.purple
        btn.frame = CGRect(x: 0, y: 100, width: 50, height: 50)
        btn.addTarget(self, action: #selector(click(sender:)), for: UIControlEvents.touchUpInside)
        self.view.addSubview(btn)
    
        btn.transform = CGAffineTransform(translationX: 50, y: self.view.bounds.size.height-150)
        
        /// 可选项绑定
        let someOpional :String? = nil
        if let constant = someOpional {
            print(constant)
        }else{
            print("someOpional is empty")
        }
        
        if let firstNumber = Int("ttt") {
            print(firstNumber)
        }else{
            print("firstNumber must be number")
        }
        
        
        /// 类型?可选项可能为空  类型！可选项,确定其中有值
        /// 隐式展开可选项
        let possibleString:String! = "i'm impossible"
        if possibleString != nil{
            print(possibleString)
        }else{
            print("possibleString is empty")
        }
        
        /// 错误处理 待探索
        do{
            try makeASandwich()
            print("no error")
        }catch {
           print("There are errors")
        }
        
        /// 断言，当判断条件为false的时候 程序会推出
        assert(true, "会崩溃啊")
    }

    func click(sender:UIButton)  {
        UIView.animate(withDuration: 1, delay: 0.0, usingSpringWithDamping:0.7, initialSpringVelocity: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
            sender.transform = CGAffineTransform.identity
        }) { (isCompelete) in
            
        }
    }
    func makeASandwich()  throws {
        //let error = NSError.init(domain: "service is crash", code: 1, userInfo: nil)
        //throw error
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
